<?php
class Subscription_model extends CI_Model {

	/**
	 * @author Pwint Phyu Shwe
	 * Subscription Model for Subscription table
	 * Subscribe/Unsubscribe/Delete and get the subscription details
	 * Refer detail in each function's comment section below.
	 */
	// table name
	private $tbl_subscription = 'subscription';

	function __construct()
	{
		// Call the Model constructor
		parent::__construct();
	}
	// get number of subscription in database
	function count_all(){
		return $this->db->count_all($this->tbl_subscription);
	}	
	// get subscription details by emailID
	function get_by_id($emailID){
		$this->db->where('emailID', $emailID);
		return $this->db->get($this->tbl_subscription);
	}
	// add new subscription
	function save($subscription){
		$this->db->insert($this->tbl_subscription, $subscription);

		if($this->db->_error_number()==1062){
    		return "DUPLICATE";
		}else{
			return $this->db->insert_id();
		}
	}
	// update details by emailID
	function update($emailID, $address){
		$this->db->where('eamilID', $emailID);
		$this->db->update($this->$tbl_subscription, $address);
	}
	// delete subscription by emailID
	function delete($emailID){
		$this->db->where('emailID', $emailID);
		$this->db->delete($this->$tbl_subscription);
	}
	//check email exist
	function check_email($emailID){
		$this->db->where('emailID', $emailID);
		$query =  $this->db->get($this->tbl_subscription);
		if ($query->num_rows() > 0)
			return true;
		else
			return false;
	}
}
?>